package com.finer.service.impl;

import com.finer.dao.SysLogDao;
import com.finer.entity.ResponseMessage;
import com.finer.entity.document.FinerGoodUnit;
import com.finer.entity.document.SysLog;
import com.finer.service.SysLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (SysLog)表服务实现类
 *
 * @author makejava
 * @since 2024-10-23 11:07:13
 */
@Service("sysLogService")
@Slf4j
@Transactional
public class SysLogServiceImpl implements SysLogService {
    @Resource
    private SysLogDao sysLogDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SysLog queryById(Integer id) {
        return this.sysLogDao.queryById(id);
    }


    /**
     * 新增数据
     *
     * @param sysLog 实例对象
     * @return 实例对象
     */
    @Override
    public SysLog insert(SysLog sysLog) {
        this.sysLogDao.insert(sysLog);
        return sysLog;
    }

    /**
     * 修改数据
     *
     * @param sysLog 实例对象
     * @return 实例对象
     */
    @Override
    public SysLog update(SysLog sysLog) {
        this.sysLogDao.update(sysLog);
        return this.queryById(sysLog.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public ResponseMessage deleteById(Integer id) {
        log.info("SysLogServiceImpl deleteById id:{}", id);
        ResponseMessage msg = new ResponseMessage();
        if (sysLogDao.deleteById(id)>0){
            msg.setCode("200");
            msg.setMessage("删除成功");
        }else{
            msg.setCode("500");
            msg.setMessage("删除失败");
        }
        return msg;
    }

    @Override
    public ResponseMessage queryLogByPage(Map map) {
        log.info("SysLogServiceImpl queryLogByPage param:{}",map);
        ResponseMessage msg = new ResponseMessage();
        PageHelper.startPage(Integer.parseInt(map.get("pageNum").toString()),Integer.parseInt(map.get("pageSize").toString()));
        List<SysLog> sysLogs = sysLogDao.queryAllByConditions(map);
        log.info("NewsDetailServiceImpl newsDetailList result:{}",sysLogs);
        PageInfo<SysLog> pageInfo = new PageInfo<>(sysLogs);
        msg.setData(pageInfo);
        msg.setCode("200");
        return msg;
    }
}
